import Router from "@koa/router";
import z from "zod";
import { MenuController } from "../controllers/menu.controller";
import { AuthUtil } from "../utils/auth.util";
import {
  validateBody,
  validateParams,
  validateQuery,
} from "../middleware/validation";
import { dateSchema, userIdSchema } from "../validators/request.validator";

const menuRouter = new Router({
  prefix: "/api/menus",
});

// 查询本周和下周的菜单菜品关联
menuRouter.get("/weeks/dishes", MenuController.getWeeksMenuDishes);

// 获取指定日期的菜单菜品关联
menuRouter.get(
  "/:date/dishes",
  validateParams(dateSchema),
  validateQuery(userIdSchema),
  MenuController.getMenuByDate
);

// 创建/更新菜单菜品关联
menuRouter.put(
  "/:date/dishes",
  AuthUtil.isAdmin(),
  validateParams(dateSchema),
  validateBody(
    z.object({
      dishesIdList: z.array(z.number()),
    })
  ),
  MenuController.upsertMenuDishes
);

export default menuRouter;
